module EasyForm
  module I18nCache
    def i18n_cache(key)
      get_i18n_chche(key)[I18n.locale] ||= yield.freeze
    end

    def get_i18n_chche(key)
      if class_variable_defined?(:"@@#{key}")
        class_variable_get(:"@@#{key}")
      else
        class_variable_set(:"@@#{key}", {})
      end
    end
  end
end